import pandas as pd
from decimal import Decimal
import numpy as np

def input_process():
    # 指定编码格式读取.xlsx文件
    path_fh1 = r'../data/附件1：各园区典型日负荷数据.xlsx'
    path_fh2 = r'../data/附件2：各园区典型日风光发电数据.xlsx'
    path_fh3 = r'../data/附件3：12个月各园区典型日风光发电数据.xlsx'

    # 指定编码格式读取.xlsx文件
    data1 = pd.read_excel(path_fh1)
    data2 = pd.read_excel(path_fh2)
    data3 = pd.read_excel(path_fh3)

    load_A = []
    load_B = []
    load_C = []

    p_light_A = []
    p_light_C = []
    p_wind_B = []
    p_wind_C = []

    p_light_A_year = []
    p_light_C_year = []
    p_wind_B_year = []
    p_wind_C_year = []

    for i, d in enumerate(data1.values):
        load_A.append(d[1])
        load_B.append(d[2])
        load_C.append(d[3])

    # print(load_A)
    # print(load_B)
    # print(load_C)

    for i, d in enumerate(data2.values):
        if i < 2:
            continue
        p_light_A.append(d[1])
        p_light_C.append(d[3])
        p_wind_B.append(d[2])
        p_wind_C.append(d[4])

    p_light_A = [round(x * 750, 4) for x in p_light_A]
    p_light_C = [round(x * 600, 4) for x in p_light_C]
    p_wind_B = [round(x * 1000, 4) for x in p_wind_B]
    p_wind_C = [round(x * 500, 4) for x in p_wind_C]

    # print(p_light_A)
    # print(p_light_C)
    # print(p_wind_B)
    # print(p_wind_C)
    data3_column = [[] for _ in range(48)]
    for i, d in enumerate(data3.values):
        if i < 3:
            continue
        tmp = d[1:]
        for j in range(len(tmp)):
            data3_column[j % 48].append(tmp[j])

    for i, d in enumerate(data3_column):
        if i % 4 == 0:
            p_light_A_year.append(d)
        elif i % 4 == 1:
            p_wind_B_year.append(d)
        elif i % 4 == 2:
            p_wind_C_year.append(d)
        elif i % 4 == 3:
            p_light_C_year.append(d)

    p_light_A_year = [[round(x * 750, 4) for x in sub] for sub in p_light_A_year]
    p_light_C_year = [[round(x * 600, 4) for x in sub] for sub in p_light_C_year]
    p_wind_B_year = [[round(x * 1000, 4) for x in sub] for sub in p_wind_B_year]
    p_wind_C_year = [[round(x * 500, 4) for x in sub] for sub in p_wind_C_year]

    # print(p_light_A_year)
    # print(p_wind_B_year)
    # print(p_wind_C_year)
    # print(p_light_C_year)
    return {
        'load_A': load_A,
        'load_B': load_B,
        'load_C': load_C,
        'p_light_A': p_light_A,
        'p_light_C': p_light_C,
        'p_wind_B': p_wind_B,
        'p_wind_C': p_wind_C,
        'p_light_A_year': p_light_A_year,
        'p_light_C_year': p_light_C_year,
        'p_wind_B_year': p_wind_B_year,
        'p_wind_C_year': p_wind_C_year,
    }



def get_model_data():
    # 读取输入数据
    data = input_process()

    # 提取数据
    load_A = data['load_A']
    load_B = data['load_B']
    load_C = data['load_C']
    p_light_A = data['p_light_A']
    p_light_C = data['p_light_C']
    p_wind_B = data['p_wind_B']
    p_wind_C = data['p_wind_C']
    p_light_A_year = data['p_light_A_year']
    p_light_C_year = data['p_light_C_year']
    p_wind_B_year = data['p_wind_B_year']
    p_wind_C_year = data['p_wind_C_year']

    # 初始化零数组
    zeros = [0] * 24

    # 创建Load数组
    Load = np.array([load_A, load_B, load_C]).T

    # 创建P_wind数组
    P_wind = np.array([zeros, p_wind_B, p_wind_C]).T

    # 创建P_solar数组
    P_solar = np.array([p_light_A, zeros, p_light_C]).T

    # 返回所有数组
    return Load, P_wind, P_solar

# 使用函数并打印结果
